from django.db import models
from users.models import CustomUser  # 导入用户模型，关联授课教师

# 课程分类模型（比如西医综合、英语、政治等分类）
class CourseCategory(models.Model):
    name = models.CharField(max_length=100)

    def __str__(self):
        return self.name

# 授课教师模型
class Teacher(models.Model):
    user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
    introduction = models.TextField()
    # 可添加教师的头像图片字段等，如：avatar = models.ImageField(upload_to='teachers/avatars/', blank=True)

    def __str__(self):
        return self.user.username

# 课程模型
class Course(models.Model):
    title = models.CharField(max_length=200)
    description = models.TextField()
    category = models.ForeignKey(CourseCategory, on_delete=models.CASCADE)
    teacher = models.ForeignKey(Teacher, on_delete=models.CASCADE)
    cover_image = models.ImageField(upload_to='courses/covers/', blank=True)  # 课程封面图片
    video_url = models.URLField(blank=True)  # 课程视频链接（可替换为 FileField 如果是本地存储视频）
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.title